package com.dartfar.util;

import java.util.LinkedHashMap;

import com.dartfar.workflow.constant.StringVeriable;


public class StringUtils {
	/**
	 * 判断字符串是否是整数
	 * @param number
	 * @return
	 */
	public static boolean isInteger(String number) {
		boolean isNumber = false;
		if (StringUtils.isNotEmpty(number)) {
			isNumber = number.matches("^([1-9]\\d*)|(0)$");
		}
		return isNumber;
	}
	
	/**
	 *判断字符串不为空 
	 * @param str
	 * @return
	 */
	public static boolean isNotEmpty(String str){
		boolean isEmpty=true;
		if(str==null || str.trim().equals("")){
			isEmpty=false;
		}
		return isEmpty;
	}
	
	/**
	 * 删除字符串中重复字符
	 * @param str
	 * @return
	 */
	public static String removeRepeat(String str){
		StringBuffer sb = new StringBuffer();
		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
			for(String tempStr : str.split(",")) 
				map.put(tempStr, tempStr);
	        for(String tempStr : map.values()) 
	            sb.append(tempStr+",");
		return sb.substring(0,sb.length()-1);
	}
	
	/**
	 * 讲数组转成SQL认识的字符串 
	 * @param ids
	 * @return
	 */
	public static String fromArrayToStr(String[] ids){
		StringBuffer idSql = new StringBuffer();
		if(null != ids && 0 != ids.length) {
			int i = 0;
			while(i<ids.length) {
				idSql.append("'");
				idSql.append(ids[i]);
				idSql.append("'");
				i++;
				if(i != ids.length) {
					idSql.append(StringVeriable.STR_SPLIT);
				}
			}
		} else {
			idSql.append("'NULL'");
		}
		return idSql.toString();
	}
}
